#ifndef WEBVIEW_H
#define WEBVIEW_H
#include <functional>
#include <QWebEngineView>

class WebView : public QWebEngineView
{
    Q_OBJECT

public:
    typedef std::function<QWebEngineView*(QWebEnginePage::WebWindowType)> CreateWindowFunction;

    explicit WebView(QWidget* parent = nullptr);
    explicit WebView(CreateWindowFunction f, QWidget* parent = nullptr);
    ~WebView() = default;

    // 设置创建窗口的回调函数
    void setCreateWindowCallback(CreateWindowFunction f) { callback_ = f; }

protected:
    QWebEngineView* createWindow(QWebEnginePage::WebWindowType type) override;

    CreateWindowFunction callback_;
};

#endif // WEBVIEW_H
